package com.czk.queue.priorityQueue;

import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/12/9 13:53
 */
public class PriorityQueueDemo {
    public static void main(String[] args) {
        PriorityQueue<Person> pq = new PriorityQueue(10, new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                // 从小到大
                return o1.getLevel() - o2.getLevel();
                // 从打到小
               // return o2.getLevel() - o1.getLevel();
            }
        });
        Person p1 = new Person("czk", 27, 5);
        Person p2 = new Person("nzq", 27, 4);
        Person p3 = new Person("czj", 27, 3);
        pq.add(p3);
        pq.add(p1);
        pq.add(p2);

        while (!pq.isEmpty()) {
            System.out.println(pq.poll());
        }
    }
}

class Person {
    private String name;
    private Integer age;
    private Integer level;

    public Person(String name, Integer age, Integer level) {
        this.name = name;
        this.age = age;
        this.level = level;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", level=" + level +
                '}';
    }
}
